<?php

	//ladda xml-feed
//	$inputDom = new DOMDocument();
//	$inputDom->load("feed.xml");
	$inputDom = simplexml_load_file("feed.xml");
//	$data = file_get_contents("http://www.perssonponerar.se/wordpress/?feed=atom");
//	$inputDom = simplexml_load_string($data);//("http://www.perssonponerar.se/wordpress/?feed=atom");
	$inputDom->registerXPathNamespace("x", "http://www.w3.org/2005/Atom");

	//hämta ut de jag är ute efter
//	$entries = $inputDom->getElementsByTagName('entry');
	$entries = $inputDom->xpath("x:entry");

	//konvertera xml till assoc array
	$outputArr = array();
	
	$i = 1;
	foreach ($entries as $entry) {
		$singleEntry = array();

		
		$singleEntry[$entry->author->getName()] = (string)$entry->author->name;
		$singleEntry[$entry->link->getName()] = (string)$entry->link["href"];
		$singleEntry[$entry->published->getName()] = date_format(new DateTime((string)$entry->published), "F j, Y, g:i a");
		$singleEntry[$entry->summary->getName()] = (string)$entry->summary;
		$singleEntry[$entry->title->getName()] = (string)$entry->title;
/* 
  		if($entry->childNodes->length) {
			foreach($entry->childNodes as $child) {
				$singleEntry[$child->nodeName] = $child->nodeValue;
			}
		}
*/
		$outputArr[$i] = $singleEntry;
		$i++;
 	}
	
	//gör om till json
	$json = json_encode($outputArr);

	//leverera
	echo $json;
?>